/*
* Created on 11.12.2003
*/
package observations;
/**
* <code>QuantityRange</code> two quantities building a range from to. For
* example '20 $ - 50 $'.
*
* @author Sascha Hemminger
* @version 2004-09-10
*/
public class QuantityRange {
/**
* Gives a range that has no lower and no upper bound which is infinity.
*
* @return infinite range
*/
public static QuantityRange unlimited() {
return new QuantityRange(null, null);
}
private Quantity end;
private boolean isEndInclusive;
private boolean isStartInclusive;
private Quantity start;
/**
* Basic constructor constructs a QuantityRange object.
*
* @param start
* lower bound of range, null if there is no lower bound
* @param isStartInclusive
* true if lower bound is inclusive
* @param end
* upper bound of range, null if there is no upper bound
* @param isEndInclusive
* true if upper bound is inclusive
*/
public QuantityRange(Quantity start, boolean isStartInclusive,
Quantity end, boolean isEndInclusive) {
this.start = start; //null implies no lower bound
this.end = end; //null implies no upper bound
this.isStartInclusive = isStartInclusive;
this.isEndInclusive = isEndInclusive;
}
/**
* Constructs a QuantityRange object with upper and lower bound inclusive.
*
* @param start
* lower bound
* @param end
* upper bound
* @see #QuantityRange(Quantity, boolean, Quantity, boolean)
*/
public QuantityRange(Quantity start, Quantity end) {
this(start, true, end, true);
}
/**
* Tests whether the quantity is in boundaries of the range.
*
* @param value
* quantity to test
* @return true if quantity is included
*/
public boolean includes(Quantity value) {
if (end != null) {
if (value.isGreaterThan(end))
return false;
if (!isEndInclusive && value.equals(end))
return false;
}
if (start != null) {
if (value.isLessThan(start))
return false;
if (!isStartInclusive && value.equals(start))
return false;
}
return true;
}
}
|